package common;

import java.util.Vector;

public class Room {
	
	private Vector<RoomTile> tiles;
	
	private Vector<Room> adjacentRooms;
	
	private Vector<Wall> noWalls;
	
	private int value;
	
	public int ID;
	
	private boolean enabled;
	
	public int keyID;
	
	

 	public Room(RoomTile tile){
		tiles = new Vector<RoomTile>();
		tiles.add(tile);
		
		adjacentRooms = new Vector<Room>();
		
		noWalls = new Vector<Wall>();
		
		enabled = true;
		keyID = 0;
	}
 	
 	@SuppressWarnings("unchecked")
 	public Room(Room room1, Room room2){
		Vector<RoomTile> newTiles = (Vector<RoomTile>) room1.tiles.clone();
 		newTiles.addAll(room2.tiles);
 		tiles = newTiles;
 		
 		Vector<Room> newAdjRooms = (Vector<Room>) room1.adjacentRooms.clone();
 		newAdjRooms.remove(room2);
 		newAdjRooms.removeAll(room2.adjacentRooms);
 		newAdjRooms.addAll(room2.adjacentRooms);
 		newAdjRooms.remove(room1);
 		adjacentRooms = newAdjRooms;
 		for(Room room : adjacentRooms){
 			room.getAdjacentRooms().remove(room1);
 			room.getAdjacentRooms().remove(room2);
 			room.getAdjacentRooms().add(this);
 		}
 		
 		Vector<Wall> newNoWalls = (Vector<Wall>) room1.noWalls.clone();
 		newNoWalls.addAll(room2.noWalls);
 		noWalls = newNoWalls;
 		
 		ID = room1.ID;
 		enabled = true;
 		keyID = 0;
 	}
 	
 	public void addAdjacentRoom(Vector<Room> rooms){
 		adjacentRooms.addAll(rooms);
 	}
 	
 	public void addAdjacentRoom(Room room){
 		adjacentRooms.add(room);
 	}
 	
 	public void addNoWall(Node n1, Node n2){
 		noWalls.add(new Wall(n1, n2));
 	}
 	
 	
 	
 	public boolean containsNode(Node n){
 		for (RoomTile tile : tiles){
 			if (tile.containsNode(n)) return true;
 		}
 		return false;
 	}
 	
 	public Vector<RoomTile> getTiles(){
 		return tiles;
 	}
 	
 	public Vector<Wall> getNoWalls(){
 		return noWalls;
 	}
 	
 	public Vector<Room> getAdjacentRooms(){
 		return adjacentRooms;
 	}
 	
 	public boolean isEntrance(){
 		for (RoomTile tile : tiles){
			if (tile.isEntrance()) return true;
		}
 		return false;
 	}
 	
 	public boolean isExit(){
 		for (RoomTile tile : tiles){
			if (tile.isExit()) return true;
		}
 		return false;
 	}
 	
 	public boolean containsWall(Wall wall){
 		for (RoomTile tile : tiles){
			if (tile.containsWall(wall)) return true;
		}
 		return false;
 	}
 	
 	public void setValue(int v){
 		value = v;
 	}
 	
 	public int getValue(){
 		return value;
 	}
 	
 	public int size(){
 		return tiles.size();
 	}
 	
 	public void setEnabled(boolean b){
 		enabled = b;
 	}
 	
 	public boolean isEnabled(){
 		return enabled;
 	}
 	
 	public String toString(){
 		return tiles.toString();
 	}
 	
 	public boolean equals(Room r){
 		return this.ID == r.ID;
 	}
}
